package com.ruoyi.web.controller.marry;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marry.domain.TUserGold;
import com.ruoyi.marry.service.ITUserGoldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户金币管理Controller
 *
 * @author user_marry
 * @date 2020-11-25
 */
@RestController
@RequestMapping("/marry/userGold")
public class TUserGoldController extends BaseController {

    @Autowired
    private ITUserGoldService tUserGoldService;

    /**
     * 查询用户金币管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:userGold:list')")
    @GetMapping("/list")
    public TableDataInfo list(TUserGold tUserGold) {
        startPage();
        List<TUserGold> list = tUserGoldService.selectTUserGoldList(tUserGold);
        return getDataTable(list);
    }

    /**
     * 查询所有用户对应的金币管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:userGold:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll() {
        startPage();
        List<TUserGold> list = tUserGoldService.getLeaderboardOfGold();
        return getDataTable(list);
    }

    /**
     * 导出用户金币管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:userGold:export')")
    @Log(title = "用户金币管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TUserGold tUserGold) {
        List<TUserGold> list = tUserGoldService.selectTUserGoldList(tUserGold);
        ExcelUtil<TUserGold> util = new ExcelUtil<TUserGold>(TUserGold.class);
        return util.exportExcel(list, "userGold");
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:userGold:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tUserGoldService.selectTUserGoldById(id));
    }

    /**
     * 新增保存用户金币管理
     */
    @PreAuthorize("@ss.hasPermi('marry:userGold:add')")
    @Log(title = "用户金币管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TUserGold tUserGold) {
        return toAjax(tUserGoldService.insertTUserGold(tUserGold));
    }

    /**
     * 修改用户金币管理
     */
    @PreAuthorize("@ss.hasPermi('marry:userGold:edit')")
    @Log(title = "用户金币管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TUserGold tUserGold) {
        return toAjax(tUserGoldService.updateTUserGold(tUserGold));
    }

    /**
     * 删除用户金币管理
     */
    @PreAuthorize("@ss.hasPermi('marry:userGold:remove')")
    @Log(title = "用户金币管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tUserGoldService.deleteTUserGoldByIds(ids));
    }
}
